import unittest,requests

class A3Mall(unittest.TestCase):
    token = None
    #登录
    def test_A3Mall_01_login(self):
        url = 'http://10.59.9.14:7003/api/public/login'
        josn = {"username": "17331859209", "password": "zx159963"}
        login1 = requests.post(url=url, json=josn)
        print(login1.json())
        A3Mall.token=login1.json()['data']['token']
        print(A3Mall.token)
    #我的
    def test_A3Mall_02_info(self):
        url1 = 'http://10.59.9.14:7003/api/ucenter/info'
        headers = {"Auth-Token":"Bearer "+A3Mall.token}
        info = requests.get(url=url1,headers=headers)
        print(info.json())

    # 签到
    def test_A3Mall_03_send(self):
        url= 'http://10.59.9.14:7003/api/sign/send'
        headers = {"Auth-Token": "Bearer " + A3Mall.token}
        send= requests.get(url=url,headers=headers)
        print(send.json())

    #搜索
    def test_A3Mall_04_search(self):
        url = 'http://10.59.9.14:7003/api/search'
        headers = {"Auth-Token": "Bearer " + A3Mall.token}
        search = requests.get(url=url)
        print(search.json())
    #搜索列表
    def test_A3Mall_05_searchlist(self):
        url = "http://10.59.9.14:7003/api/search/list?page=1&keywords=%E7%83%AD&type=0&sort=1"
        searchlist = requests.get(url=url)
        A3Mall.spid = searchlist.json()['data']['list'][0]['id']
        print(searchlist.json())
        print(A3Mall.spid)

    #商品详情
    sell_price =None
    def test_A3Mall_06_view(self):
        url = 'http://10.59.9.14:7003/api/goods/view?id='+ str(A3Mall.spid)
        view = requests.get(url=url)
        A3Mall.sell_price = view.json()['data']['goods']['sell_price']
        print(A3Mall.sell_price)
        print(view.json())

    #添加
    def test_A3Mall_07_add(self):
        url = " http://10.59.9.14:7003/api/cart/add"
        headers = {"Auth-Token": "Bearer " + A3Mall.token}
        json = {"id": A3Mall.spid, "sku_id": "", "num": 1}
        add = requests.post(url=url,json=json,headers=headers)
        print(add.json())

    #购物车
    def test_A3Mall_08_cart(self):
        url = 'http://10.59.9.14:7003/api/cart?page=1'
        headers = {"Auth-Token": "Bearer " + A3Mall.token}
        cart = requests.get(url=url,headers=headers)
        A3Mall.gouwucheid = cart.json()['data']['list'][0]['id']
        print(cart.json())

    #立即购买
    def test_A3Mall_09_confrim(self):
        url= 'http://10.59.9.14:7003/api/order/confirm?id='+ str(A3Mall.gouwucheid) +'&type=cart&shipping_type=1'
        headers = {"Auth-Token": "Bearer " + A3Mall.token}
        confrim = requests.get(url=url,headers=headers)
        A3Mall.goods_id = confrim.json()['data']['item'][0]['goods_id']
        print(A3Mall.goods_id)
        print(confrim.json())
    #创建订单

    def test_A3Mall_10_create(self):
        url= 'http://10.59.9.14:7003/api/order/create'
        headers = {"Auth-Token": "Bearer " + A3Mall.token}
        json = {"id":A3Mall.gouwucheid ,"type":"cart","address_id":176,"store_id":"0","shipping_type":1,"bonus_id":"0","payment":"balance","remarks":"","source":1,"url":"http://10.59.9.14:7003/wap/pages/cart/confirm?id=14&type=cart"}
        create = requests.post(url=url,headers=headers,json=json)
        print(create.json())
if __name__ == '__main__':
    unittest.main()